<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateAddressTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('think_address');
        $table
            ->addColumn('user_id', 'integer', ['comment' => '用户ID'])
            ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '收货人姓名'])
            ->addColumn('phone', 'string', ['limit' => 20, 'default' => '', 'comment' => '收货人手机号'])
            ->addColumn('province', 'string', ['limit' => 50, 'default' => '', 'comment' => '省'])
            ->addColumn('city', 'string', ['limit' => 50, 'default' => '', 'comment' => '市'])
            ->addColumn('district', 'string', ['limit' => 50, 'default' => '', 'comment' => '区/县'])
            ->addColumn('address', 'string', ['limit' => 255, 'default' => '', 'comment' => '详细地址'])
            ->addColumn('is_default', 'boolean', ['default' => 0, 'comment' => '是否默认地址'])
            ->addColumn('created_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
            ->addColumn('updated_at', 'datetime', ['null' => true, 'comment' => '更新时间'])
            ->create();
    }
}
